package Student_Course;

import Main.UserLogin;

import java.sql.*;


public class CourseDelete {
    public void deleteCourse(int id) throws SQLException {
        String url = "jdbc:sqlserver://localhost:1433;databaseName=Student_Grade_Management_System;trustServerCertificate=true";
        String user = "ysy";
        String password = "051018";
        Connection conn = DriverManager.getConnection(url, user, password);
        String query = "DELETE FROM 选课信息 WHERE 课程编号 = ? AND 学号 = ?";
        try (
                PreparedStatement ps = conn.prepareStatement(query)) {
            String myId = UserLogin.getUserId();
            ps.setInt(1, id);
            ps.setString(2, myId);
            ps.executeUpdate();
            System.out.println("课程退选成功！");

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
